import taInfiniteScroll from './ta-infinite-scroll/index.js'

// taui
import taCmEditor from './ta-cm-editor'
import taQuickPopup from './ta-quick-popup'
import taTableCard from './ta-table-card'
import taMediaSelect from './ta-media-select'
import taJsonSchemaTree from './ta-json-schema-tree'
import taEditableCell from './ta-editable-cell'
import taDesigner from './ta-designer'

import taCascader from './ta-cascader'
import taSelectFilter from './ta-select-filter'

import taTagPlus from './ta-tag-plus'
import taDatepicker from './ta-datepicker'

export default {
	install: (app) => {

		app.config.globalProperties.$request = function(key, defaultVal = null) {
			const params = new URLSearchParams(window.location.search);
			const result = {};
			for (const [key, value] of params.entries()) {
				const decodedKey = decodeURIComponent(key);
				const decodedValue = decodeURIComponent(value);

				if (result[decodedKey]) {
					result[decodedKey] = Array.isArray(result[decodedKey]) ? [...result[decodedKey],
						decodedValue
					] : [result[decodedKey], decodedValue];
				} else {
					result[decodedKey] = decodedValue;
				}
			}
			return result[key] !== undefined ? result[key] : defaultVal;
		}

		/* taui directive */
		app.directive('InfiniteScrollV2', taInfiniteScroll)

		/* taui component */
		app.component('taCmEditor', taCmEditor);
		app.component('taQuickPopup', taQuickPopup);
		app.component('taTableCard', taTableCard);
		app.component('taJsonSchemaTree', taJsonSchemaTree);
		app.component('taEditableCell', taEditableCell);
		app.component('taDesigner', taDesigner);
		app.component('taMediaSelect', taMediaSelect);
		app.component('taCascader', taCascader);
		app.component('taTagPlus', taTagPlus);
		app.component('taDatepicker', taDatepicker);
		app.component('taSelectFilter', taSelectFilter);

	}
}
